package mysql

import "database/sql"

type SqlTransaction struct {
	Transaction_handle *sql.Tx
	Transaction_err error
}

func (self *SqlTransaction)GetSqlOperate(sql string) *SqlCommond{
	if self.Transaction_err != nil{
		return &SqlCommond{
			Sql_handle: nil,
			Sql_err:self.Transaction_err,
		}
	}
	handle,err := self.Transaction_handle.Prepare(sql)
	return &SqlCommond{
		Sql_handle: handle,
		Sql_err:err,
	}
}

func (self *SqlTransaction) Commit() error{
	if self.Transaction_err != nil{
		return self.Transaction_err
	}
	return self.Transaction_handle.Commit()
}

func (self *SqlTransaction) Rollback() error{
	if self.Transaction_err != nil{
		return self.Transaction_err
	}
	return self.Transaction_handle.Rollback()
}